<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c-rt:set var="frontContextPath" value='<%=ServerValue.getFrontContextPath()%>'/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="UTF-8" src="/js/jquery.timers-1.2.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<Style>
li.w-1of1{overflow:hidden}
</style>
<script language="javascript">
	$().ready(function(){

		$("#mMobile").numeric();
		if("${member.mobile}"==""){
			$("#current_location").html('&nbsp;&gt;&nbsp;<a href="${frontContextPath}/member/modifydata.do">个人信息管理&nbsp;-&nbsp;修改个人信息</a>&nbsp;&gt;&nbsp;新增手机号码');
		}else{
			$("#current_location").html('&nbsp;&gt;&nbsp;<a href="${frontContextPath}/member/modifydata.do">个人信息管理&nbsp;-&nbsp;修改个人信息</a>&nbsp;&gt;&nbsp;修改手机号码');
		}
		$("#m_modifyData").css("font-weight","bold");

		$("#sdialog").dialog({
			autoOpen: false,
			bgiframe: true,
			height: 150,
			width:325,
			modal: true
		});

		$("#mdialog").dialog({
			autoOpen: false,
			bgiframe: true,
			height: 220,
			width:470,
			modal: true
		});

		$("#crmcheckdialog").dialog({
			autoOpen: false,
			bgiframe: true,
			width: 380,
			height: 'auto',
			modal: true,
			resizable: false 
		});

		$('#mcommit').click(function(){
			checkMobile(1);
		});

		$("#mMobile").blur(function(){
			checkMobile(0);
		});

		$("#crmClose").click(function(){
			$("#crmcheckdialog").dialog('close');
		});

		if("${actionResult}" == "resend_success"){
			$("#sdialog").dialog('open');
		}else if("${actionResult}" == "mobile_exist"){
			$("#smsg").text('发送简讯失败');
			$("#sdialog").dialog('open');
		}else if("${actionResult}" == "ccode_error"){
			$("#ccodeTip").text('校验码无效');
			$("#ccodeTip").show();
		}

		var left = 30;
		if(parseInt('${member.mobileModifyCount}')<10){
			if("${actionResult}" == "modify_send_success" || "${actionResult}" == "resend_success" || "${actionResult}" == ""){
				$('body').everyTime('1s',function(){
					if(left==0){
						$('body').stopTime ();
						$('#resend').removeAttr('disabled');
						$('#resend').val('点此重发校验码');
						return;
					}
					$('#resend').val('请于'+left+'秒后点此重发校验码');
					left--;
				});
			}else{
				left=0;
				$('#resend').removeAttr('disabled');
				$('#resend').val('点此重发校验码');
			}
		}else{
			$('#resend').val('点此重发校验码');
		}
				
		$('#resend').click(function(){
			//重发
			window.location.replace("${frontContextPath}/member/gomodifymobile.do");
		});

		$("#sclose").click(function(){
			$("#sdialog").dialog('close');
		});

		$("#goactivate").click(function(){
			$("#ccodeTip").hide();
			if($("#ccode").val().length==0){
				$("#ccodeTip").text('请输入校验码');
				$("#ccodeTip").show();
				return;
			}else if($("#ccode").val().length!=8){
				$("#ccodeTip").text('校验码错误');
				$("#ccodeTip").show();
				return;
			}
			$.post("${frontContextPath}/jsonCheckActivateMobileCode.do",{memberId:'${member.memberId}',ccode:$("#ccode").val()},
					function callback(result){
						if(result!=''){
							$("#ccodeTip").text('校验码错误');
							$("#ccodeTip").show();
						}else{
							$("#toMobileActivateForm").submit();
							return false;
						}
					},
					"json");
			return false;
		});

		$("#modifyMobile").click(function(){
			if(left==0){
				$("#mobileTip").hide();
				$("#mMobile").val('');
				$("#mdialog").dialog('open');
			}
		});

		$("#goCrmCheck").click(function(){
			$.post("<%=ServerValue.getFrontContextPath()%>/jsonCrmCheckMobile.do",{mobile:'${member.tempMobile}',memberId:'${member.memberId}',from:'1'},
					function callback(result){
						if(result=='empty'){
							alert('您目前无待验证手机');
						}else if(result!=''){
							$("#questionId").text(result);
							$("#crmcheckdialog").dialog('open');
						}
					},
					"json");
		});
	});
	function checkMobile(is_submit){
		$("#mobileTip").hide();
		var text = $("#mMobile").attr('value');
		if(text.length==0){
			$("#mobileTip").html("请输入手机号码");
			$("#mobileTip").show();
		}else if(text.length!=11){
			$("#mobileTip").html("手机号码格式错误");
			$("#mobileTip").show();
		}else {
			$.post("<%=ServerValue.getFrontContextPath()%>/checkRegData.do",{c_id:4,mobile:text},
					function callback(result){
						if(result=='exist'){
							$("#mobileTip").html("此手机号码已注册");
							$("#mobileTip").show();
						}else {
							if(is_submit == 1){
								$("#sendMobile").val($("#mMobile").val());
								$("#resendForm").submit();
								return false;
							}
						}
					},
					"json");
		}
	}
</script>
</head>
<body>
<div id="sdialog" title="成功发送手机短信" class="member-reg-alert-ok" style="display:none;">
  <p id="smsg">已经向您的手机<span class="txt-rd"><strong>${member.tempMobile}</strong></span><br />
  发送免费的验证短信。</p>
  <div align="center"> <span style="text-align:center;"><a href="javascript:;" class="btn-mid" id="sclose">关闭</a></span> </div>
</div>
<c:if test="${empty member.mobile}">
<div id="mdialog" title="更改手机号码" class="m-regform" style="display:none;">
<style type="text/css">.m-regform{ padding:25px 15px; } .m-regform li{ margin:0; list-style-type:none; } .w-head{ width:135px; font-size:14px; }</style>
  <p>更换号码后将会重新发送校验码。</p>
  <ul>
      <li class="w-1of1" style="padding-top:1em;"><div class="w-head">要更换的手机号码：</div><div style="margin-top:-1em;"><strong class="ipt-w20"><input type="text" id="mMobile" maxlength="11"/></strong><span style="display:block;"><span class="msg rn" id="mobileTip" style="display:none;">请输入手机号</span></span></div></li>
  </ul>
  <div align="center"><a href="javascript:;" class="btn-mid" id="mcommit">确认</a></div>
</div>
</c:if>
<div id="crmcheckdialog" title="手机验证" class="phone-area dailog-ok" style="display:none;">
	<p>您已请求客服人工验证<br />联络手机号码：<span class="txt-rd">${member.tempMobile}</span><br />请保持接听畅通，我们会在24小时内联络上述号码。<br />您也可致电4001-168-100，请客服人工验证，案件编<br />号：<span class="txt-rd" id="questionId"></span>。<br />耀点100真心感谢您的支持！</p>
    <div align="center">
         <span style="text-align:center;"><a class="btn-mid" href="javascript:;" id="crmClose">关闭</a></span>
    </div>
</div>
<h2><span class="location"><c:choose>
<c:when test="${empty member.mobile}">新增手机号码</c:when>
<c:otherwise>修改手机号码</c:otherwise>
</c:choose></span></h2>
    <!-- 內容 -->
    <div class="change-email">
        <p class="c-f LH-1of5">&nbsp;</p>
        <p class="txt-L">&nbsp;</p>
        <p class="txt-m" style="margin-left:100px;">校验码短信已发送到您的手机，请输入校验码：</p>
        <s:form action="modifyMobileActivate.do" method="post" id="toMobileActivateForm">
        <div class="d-show">
  		  <ul style="margin-left:50px;">
  		  	  <li class="w-1of1"><div class="field-title"><strong>手机号码：</strong></div><div><span class="txt-rd" style="font-size:14px;">${member.tempMobile}</span>&nbsp;&nbsp;<c:if test="${empty member.mobile && member.mobileModifyCount < 10}"><a href="javascript:;" id="modifyMobile">更换号码</a></c:if></div></li>
              <li class="w-1of1" style="padding-top:.75em;"><div class="field-title"><strong>校验码：</strong></div><div style="margin-top:-.75em;"><strong class="ipt-w20"><input type="text"  id="ccode" name="ccode" maxlength="8" /></strong><span style="display:block"><span class="msg rn" style="display:none" id="ccodeTip">校验码无效</span></span></div></li>
          </ul>
      	</div>
        <p align="center"><a href="javascript:;" class="btn-mid" id="goactivate">确定</a></p>
        </s:form>
        <p align="center">&nbsp;</p>
        <p align="center">&nbsp;</p>
        <ul style="margin-left:74px;overflow:auto;zoom:1;">
        	<li class="w-1of1">如果您<c:if test="${actionResult == 'resend_success' || actionResult == 'modify_send_success' || empty actionResult}">在30秒内</c:if>没有收到校验码，<input type="submit" name="button" id="resend" value="请于30秒后点此重发校验码" class="btn-reg-phone"  disabled="disabled"/><c:if test="${member.mobileModifyCount >= 10}">(已达使用次数上限)</c:if></li>
            <li class="w-1of1">&nbsp;</li>
        	<c:if test="${member.mobileModifyCount >= limitMobileRegTimes && not empty member.tempMobile}"><li class="w-1of1">收不到短信？您还可以&nbsp;<input type="button" value="点击请求客服人工验证" class="btn-reg-phone" id="goCrmCheck"/></li></c:if>
        </ul>
    </div>
    <!-- 內容 -->
    <!-- 注意事项 -->

    <div class="txt-note">
     <p><strong>【提示】</Strong></p>
      <ul>
        <li>．校验码短信已发送，请查阅您的手机短信。</li>
        <li>．耀点100给您发送的手机校验码短信是免费的。</li>
        <li>．每个帐户进行手机验证，一个月内使用短信最多10次。</li>
      </ul>
    </div>
    <!-- 注意事项 -->
<s:form action="gomodifymobile.do" method="post" id="resendForm">
  <input type="hidden" id="sendMobile" name="mobile">
</s:form>
</body>
</html>